package org.glut.config;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Component;

import java.util.Collection;
@Component
public class MyUserDetils implements UserDetails {
    private String username;    //账号
    private  String password;   //密码
    private boolean accountNonExpired;  //是否没过期
    private boolean accountNonLocked;   // 是否被锁定 (这里只用这个来判断)
    private boolean credentialsNonExpired;
    private boolean enabled;
    private Collection<? extends GrantedAuthority> authorities;

    public void setAuthorities(Collection<? extends GrantedAuthority> authorities) {
        this.authorities = authorities;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public void setAccountNonExpired(boolean accountNonExpired) {
        this.accountNonExpired = accountNonExpired;
    }

    public void setAccountNonLocked(boolean accountNonLocked) {
        this.accountNonLocked = accountNonLocked;
    }

    public void setCredentialsNonExpired(boolean credentialsNonExpired) {
        this.credentialsNonExpired = credentialsNonExpired;
    }

    public void setEnabled(boolean enabled) {
        this.enabled = enabled;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @Override
    public String getPassword() {
        return password;
    }

    @Override
    public String getUsername() {
        return username;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;        //不使用这个验证，直接返回
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;    //不使用这个验证，直接返回
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;    //不使用这个验证，直接返回
    }

    @Override
    public boolean isEnabled() {
        return enabled;     //只使用账号是否被锁定来判断
    }
}
